﻿package com.wandian.view.components.ui
{
	import com.wandian.data.GameData;
	import com.wandian.model.*;
	import com.wandian.model.vo.*;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.LoadIconUtil;
	import com.wandian.util.loader.ImageLoader;

	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class GiveGiftPlayer extends EventDispatcher
	{
		private var _mcPlayer:MovieClip;
		private var _playerVo:PlayerVo;
		private var _isSelected:Boolean=false;

		public function GiveGiftPlayer(mcPlayer:MovieClip, playerVo:PlayerVo)
		{
			this._mcPlayer=mcPlayer;
			if (playerVo==null)
			{
				this._playerVo=new PlayerVo();
			}
			else
			{
				this._playerVo=playerVo;
			}
			this.init();
			return;
		}

		private function init():void
		{
			while (this._mcPlayer.pic_mc.numChildren)
			{

				this._mcPlayer.pic_mc.removeChildAt(0);
			}
			if (this._playerVo.userid == 0)
			{
				return;
			}
			if (this._playerVo.sex == 1)
			{
				CLZLoadIcon.addIcon(this._mcPlayer.pic_mc, this._playerVo.icon, 50, 50, 0, 0, "InitPicGirlIcon", false, false);
			}
			else
			{
				CLZLoadIcon.addIcon(this._mcPlayer.pic_mc, this._playerVo.icon, 50, 50, 0, 0, "InitPicBoyIcon", false, false);
			}
			this._mcPlayer.name_txt.text=this._playerVo.name;
			this._mcPlayer.gotoAndStop(1);
			this._mcPlayer.buttonMode=true;
			this._mcPlayer.addEventListener(MouseEvent.CLICK, this.onPlayerHandler);
			return;
		}

		private function onPlayerHandler(event:MouseEvent=null):void
		{
			if (this._isSelected)
			{
				this._isSelected=false;
				this._mcPlayer.gotoAndStop(1);
			}
			else
			{
				this._isSelected=true;
				this._mcPlayer.gotoAndStop(2);
			}
			this.dispatchEvent(new Event(Event.CHANGE));
			return;
		}

		public function set selectPlayer(param1:Boolean):void
		{
			this._isSelected=param1;
			if (this._isSelected)
			{
				this._mcPlayer.gotoAndStop(2);
			}
			else
			{
				this._mcPlayer.gotoAndStop(1);
			}
			return;
		}

		public function get selected():Boolean
		{
			return this._isSelected;
		}

		public function get playerVo():PlayerVo
		{
			return this._playerVo;
		}

	}
}
